﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TMIS.Reports;
using DevExpress.XtraEditors;

namespace TMIS
{
    public partial class frmApproval : frmCommon
    {
        public Guid guid = Guid.Empty;
        private BLL.Approval bll = new BLL.Approval();
        public frmApproval()
        {
            InitializeComponent();
        }
        public frmApproval(Guid guid)
        {
            this.guid = guid;
            InitializeComponent();
            this.FillComponent();
        }
        /// <summary>
        /// 控件信息数据初始化
        /// </summary>
        private void FillComponent()
        {
            Model.Approval app = bll.Get(guid);
            txtContext.Text = app.Context;
            txtLiterature.Text = app.Literature;
            chkOpenReport.Checked = Convert.ToBoolean(app.OpenReport);
            chkDocument.Checked = Convert.ToBoolean(app.Document);
            chkInternship.Checked = Convert.ToBoolean(app.Internship);
            chkInstruction.Checked = Convert.ToBoolean(app.Instructe);
            txtOther.Text = app.Other;
            BeginDate.Text = Convert.ToDateTime(app.BeginDate).ToShortDateString();
            CompleteDate.Text = Convert.ToDateTime(app.CompleteDate).ToShortDateString();
            this.Priview();

        }
        public override void Save()
        {
            Model.Approval approval = new Model.Approval()
            {
                ID = this.guid,
                Context = txtContext.Text,
                Literature = txtLiterature.Text,
                OpenReport = chkOpenReport.Checked,
                Document = chkDocument.Checked,
                Internship = chkInternship.Checked,
                Instructe = chkInstruction.Checked,
                Other = txtOther.Text,
                BeginDate = Convert.ToDateTime(BeginDate.Value),
                CompleteDate = Convert.ToDateTime(CompleteDate.Value)
            };
            bll.Update(approval);
        }

        public override void Priview()
        {
            this.approvalTableAdapter.FillByStudentID(this.reportDS.Approval, guid);
            this.reportViewer.RefreshReport();
        }
    }
}
